package com.ruoyi.base.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.base.util.GenCodeUtils;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.impl.SysRoleServiceImpl;
import com.ruoyi.system.service.impl.SysUserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.base.mapper.TeamManagementMapper;
import com.ruoyi.base.domain.TeamManagement;
import com.ruoyi.base.service.ITeamManagementService;

/**
 * 班组管理Service业务层处理
 * 
 * @author linchong
 * @date 2022-08-16
 */
@Service
public class TeamManagementServiceImpl implements ITeamManagementService 
{
    @Autowired
    private TeamManagementMapper teamManagementMapper;
    @Autowired
    private SysUserServiceImpl sysUserService;
    @Autowired
    private SysRoleServiceImpl sysRoleService;

    /**
     * 查询班组管理
     * 
     * @param id 班组管理主键
     * @return 班组管理
     */
    @Override
    public TeamManagement selectTeamManagementById(Long id)
    {
        return teamManagementMapper.selectTeamManagementById(id);
    }

    /**
     * 查询班组管理列表
     * 
     * @param teamManagement 班组管理
     * @return 班组管理
     */
    @Override
    public List<TeamManagement> selectTeamManagementList(TeamManagement teamManagement)
    {
        return teamManagementMapper.selectTeamManagementList(teamManagement);
    }

    /**
     * 新增班组管理
     * 
     * @param teamManagement 班组管理
     * @return 结果
     */
    @Override
    public int insertTeamManagement(TeamManagement teamManagement) {
        //生成班组编号
        teamManagement.setTeamNo(GenCodeUtils.getTeamNo());
        teamManagement.setCreateTime(DateUtils.getNowDate());
        SysUser user = SecurityUtils.getLoginUser().getUser();
        teamManagement.setCreateBy(user.getUserName());
        teamManagement.setCreateRole(user.getRoles().get(0).getRoleName());
        return teamManagementMapper.insertTeamManagement(teamManagement);
    }


    /**
     * 修改班组管理
     * 
     * @param teamManagement 班组管理
     * @return 结果
     */
    @Override
    public int updateTeamManagement(TeamManagement teamManagement) {
        return teamManagementMapper.updateTeamManagement(teamManagement);
    }

    /**
     * 批量删除班组管理
     * 
     * @param ids 需要删除的班组管理主键
     * @return 结果
     */
    @Override
    public int deleteTeamManagementByIds(Long[] ids)
    {
        return teamManagementMapper.deleteTeamManagementByIds(ids);
    }

    /**
     * 删除班组管理信息
     * 
     * @param id 班组管理主键
     * @return 结果
     */
    @Override
    public int deleteTeamManagementById(Long id) {
        return teamManagementMapper.deleteTeamManagementById(id);
    }

    @Override
    public int teamStatusEnable(Long[] ids) {
        return teamManagementMapper.teamStatusEnable(ids);
    }

    @Override
    public int teamStatusDisable(Long[] ids) {
        return teamManagementMapper.teamStatusDisable(ids);
    }

    @Override
    public int teamStatusChange(Long id, String teamStatus) {
        return teamManagementMapper.teamStatusChange(id,teamStatus);
    }
}
